<!doctype html>
<html>
<head>
<?php $this->load->view('common_head'); ?>
<link href="<?php echo base_url(); ?>themes/site/default/css/dev/register.css?v=<?php echo UI_VERSION; ?>" rel="stylesheet" />
</head>
<body>
<div class="wrap">
	<?php $this->load->view('common_header'); ?>
	<div class="main_wrap">
		<div class="main">
			<div class="box_wrap register cc">
				<h2 class="reg_head">登录</h2>
				<div class="reg_cont_wrap">
					<div class="reg_cont">
						<?php echo form_open('user/login', array('id' => 'J_u_login_form')); ?>
							<input type="hidden" name="ref" value="<?php echo $this->input->get('ref', TRUE); ?>" />
							<div class="reg_form">
								<div class="tips"><span class="tips_icon">请登录后再继续浏览</span></div>
								<dl class="cc">
									<dt><label for="J_u_login_username">帐号：</label></dt>
									<dd><input type="text" tabindex="1" value="" aria-required="true" class="input length_4" name="username" data-id="username" id="J_u_login_username"></dd>
									<dd class="dd_r" aria-hidden="true" role="tooltip" id="J_u_login_tip_username"><span class="tips_icon_success"><span></span></span></dd>
								</dl>
								<dl class="cc">
									<dt><label for="J_u_login_password">密码：</label></dt>
									<dd><input type="password" tabindex="2" value="" class="input length_4" aria-required="true" name="password" data-id="password" id="J_u_login_password"></dd>
									<dd class="dd_r">
										<span aria-hidden="true" role="tooltip" id="J_u_login_tip_password"></span>
									</dd>
								</dl>
								<div style="display:none;" id="J_login_qa"></div>
								<dl class="cc pick">
									<dt>&nbsp;</dt>
									<dd><a tabindex="7" class="fr mr10" href="<?php echo site_url(); ?>user/findpwd" rel="nofollow">找回密码</a><input type="checkbox" tabindex="9" id="cktime" class="checkbox" name="rememberme"><label for="cktime">自动登录</label></dd>
								</dl>
								<dl class="cc">
									<dt>&nbsp;</dt>
									<dd><button tabindex="10" type="submit" class="btn btn_big btn_submit mr20">登录</button>
									</dd>
								</dl>
							</div>
						<?php echo form_close(); ?>
					</div>
				</div>
				<div class="reg_side">
					<div class="reg_side_cont">
						<p class="mb10">还没有帐号？</p>
						<p><a tabindex="8" class="btn btn_big" href="<?php echo base_url(); ?>user/register" rel="nofollow">免费注册</a></p>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!--.main-wrap,#main End-->
	<?php $this->load->view('common_footer'); ?>
</div>
<script>
Wind.use('jquery', 'global', 'validate', 'ajaxForm', function(){
	//聚焦时默认提示
	var focus_tips = {
		username : '用户名',
		password : '用户密码',
	};

	var _statu = '',
		login_tip_username = $('#J_u_login_tip_username');

	var u_login_form = $("#J_u_login_form"),
			u_login_username = $('#J_u_login_username');

	u_login_form.validate({
		errorPlacement: function(error, element) {
			//错误提示容器
			$('#J_u_login_tip_'+ element[0].name).html(error);
		},
		errorElement: 'span',
		errorClass : 'tips_icon_error',
		validClass : 'tips_icon_success',
		onkeyup : false, //remote ajax
		focusInvalid : false,
		rules: {
			username: {
				required : true,
				//中文字节数限制，util_libs/validate.js 的扩展提示需要修改，pw9正式版后不知道会不会修复
				byteRangeLength : [3,15],
				remote : {
					url : '<?php echo base_url(); ?>user/checkname',
					//beforeSend : '', //取消startRequest方法
					dataType: "json",
					type : 'post',
					data : {
						'username' : function(){
							return u_login_username.val();
						},
						<?php echo $this->security->get_csrf_token_name(); ?> : function(){
							return '<?php echo $this->security->get_csrf_hash(); ?>';
						}
					}
				}
			},
			password : {
				required : true
			}
		},
		highlight : false,
		unhighlight	: function(element, errorClass, validClass) {
			if(element.name === 'password') {
				$('#J_u_login_tip_password').html('');
				return;
			}
			//$('#J_u_login_tip_'+ $(element).data('id')).html('<span class="'+ validClass +'" data-text="text"><span>');
		},
		onfocusin	: function(element){
			var name = element.name;
			$(element).parents('dl').addClass('current');
			$('#J_u_login_tip_'+ name).html('<span class="reg_tips" data-text="text">'+ focus_tips[name] +'</span>');
		},
		onfocusout	:  function(element){
			$(element).parents('dl').removeClass('current');
			//$('#J_u_login_tip_'+ $(element).data('id')).html('');
			if(element.name === 'username'){
				this.element(element);
			}
		},
		messages : {
			username : {
				required : '帐号不能为空'
			},
			password : {
				required : '密码不能为空'
			}
		},
		submitHandler:function(form) {
			var btn = $(form).find('button:submit');
			
			$(form).ajaxSubmit({
				dataType : 'json',
				beforeSubmit : function(){
					//global.js
					ajaxBtnDisable(btn);
				},
				success : function(data, statusText, xhr, $form) {
					if(data.state === 'success') {
							window.location.href = data.referer;
					}else if(data.state === 'fail'){
						//global.js
						ajaxBtnEnable(btn);
						//global.js
						Wind.Util.resultTip({
							elem : btn,
							error : true,
							msg : data.message[0],
							follow : true
						});
					}
				}
			});
		}
	});

	//聚焦第一个input
	u_login_form.find('input.input:visible:first').focus();

});
</script>
</body>
</html>